package com.fenqing.bean;

import cn.hutool.json.JSONUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * @author fenqing
 */
public class TreeNode {
    public int val;
    public TreeNode left;
    public TreeNode right;

    public TreeNode() {
    }

    public TreeNode(int val) {
        this.val = val;
    }

    TreeNode(int val, TreeNode left, TreeNode right) {
        this.val = val;
        this.left = left;
        this.right = right;
    }

    @Override
    public String toString() {

        List<Object> arr = new ArrayList<>();
        arr.add(val);
        String ls = this.left == null ? "[]" : this.left.toString();
        arr.addAll(JSONUtil.parseArray(ls));
        String rs = this.right == null ? "[]" : this.right.toString();
        arr.addAll(JSONUtil.parseArray(rs));
        return JSONUtil.toJsonStr(arr);
    }
}